﻿using System;
using System.Collections.Generic;
using System.Linq; 
using NTTDATA.BEENChina.ResultCertification.Config;

namespace NTTDATA.BEENChina.ResultCertification.Checker.Date
{
    [Serializable]
    [VerfityAttribute(Id = "VerfityRq0211", Name = "入退院栏检证_2", CategoryType = EnumCategoryType.日期, Model = true)]
    public class VerfityRq0211:VerfityOneResult
    {
        /// <summary>
        /// 人退院栏出现复数选择时
        /// 抽出检证
        ///
        /// 条件追加
        /// 或者
        /// 入退院栏出现[1 2 ？]以外的记载时抽出
        /// 
        /// 2013 10 08 增加条件
        /// 在入退院栏不为空的前提下检验
        /// </summary>
        /// <param name="result"></param>
        /// <param name="entryCommon"></param>
        /// <returns></returns>
        public override bool CheckResult(List<List<string>> result, string entryCommon)
        {
            bool bresult = false;

              List<string> hospitals = new List<string>();

            int hospitalResultIndex =
             ChildImageObject.CategorySetting.DataFormat.Split('/').ToList().IndexOf("tx");
            

            foreach (var rowResult in result)
            {

                if (rowResult.Count >= 2)
                {
                    string colResult1 = rowResult[0];
                    //string hos;

                    if (colResult1.Split('/').Length > hospitalResultIndex)
                    {                 
                        if  ( EmptyResultCount(colResult1) == 0)
                        {
                            string hx =
                                new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult1).
                                    GetHospital();

                            if (!String.IsNullOrEmpty(hx))
                            {
                                hospitals.Add(hx);
                            }
                        }
                    }


                    string colResult2 = rowResult[1];
                    
                    if (colResult2.Split('/').Length > hospitalResultIndex)
                    {
                        if (EmptyResultCount(colResult2) == 0)
                        {
                            string hx =
                                new Split.SplitEntryResult(ChildImageObject.CategorySetting.DataFormat, colResult2).
                                    GetHospital();

                            if (!String.IsNullOrEmpty(hx))
                            {
                                hospitals.Add(hx);
                            }
                        }
                    } 

                }
  
            }



            if (hospitals.Any())
            {
               bresult = (hospitals.Count(t => t.Contains(".")) > 0);
               if (!bresult)
               {
                   bresult = hospitals.Any(o => o !="?" && o!="1" && o!="2");
               }
            }


            if (bresult)
            {
                System.Console.WriteLine("VerfityRq0211");
            }

            return bresult;   
        }
         

        

    }
}